﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.ThreeSelectWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.ThreeSelectWay
{
    public class ShowCityCommandHandler : IRequestHandler<ShowCityCommand, ApiResult<List<Slaughts_City>>>
    {
        IBaseReponsitory<Slaughts_City> Slaughts_City;

        public ShowCityCommandHandler(IBaseReponsitory<Slaughts_City> Slaughts_City)
        {
            this.Slaughts_City = Slaughts_City;
        }

        public async Task<ApiResult<List<Slaughts_City>>> Handle(ShowCityCommand request, CancellationToken cancellationToken)
        {
            var list = await Slaughts_City.GetQuery().Where(c=>c.Sheng_Id==request.ShengId).ToListAsync();
            return new ApiResult<List<Slaughts_City>>
            {
                Code = ApiEnum.False,
                Message = "成功了",
                Data = list
            };
        }
    }
}
